// Author: wsfuyibing <682805@qq.com>
// Date: 2025-05-21

package seat

import (
	"gitee.com/go-libs/db-xorm/db"
	"server/app/errs"
	"server/app/http/models"
	"server/app/kind"
)

type Logic struct{}

func (o *Logic) CalcEnables(sess *db.Session, id int64) (count int64, err error) {
	if count, err = sess.Where("pond_id = ? AND enabled = ? AND deleted = ?", id, kind.EnabledYes, kind.DeletedNo).Count(models.ArcadePondSeat{}); err != nil {
		err = errs.ErrDatabaseQuery
	}
	return
}

func (o *Logic) CalcTotal(sess *db.Session, id int64) (count int64, err error) {
	if count, err = sess.Where("pond_id = ? AND deleted = ?", id, kind.DeletedNo).Count(models.ArcadePondSeat{}); err != nil {
		err = errs.ErrDatabaseQuery
	}
	return
}

func (o *Logic) CalcUpdate(sess *db.Session, id int64, total, enables int64) (err error) {
	if _, err = sess.Cols("seat_total", "seat_count").Where("id = ?", id).Update(&models.ArcadePond{
		SeatTotal: int(total),
		SeatCount: int(enables),
	}); err != nil {
		err = errs.ErrDatabaseQuery
	}
	return
}
